package com.ruoyi.mx.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.mx.domain.MxActivity;
import com.ruoyi.mx.service.IMxActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 美秀活动Controller
 *
 * @author ruoyi
 * @date 2021-09-27
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mx/activity" )
public class MxActivityController extends BaseController {

    private final IMxActivityService iMxActivityService;

    /**
     * 查询美秀活动列表
     */
    @PreAuthorize("@ss.hasPermi('mx:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(MxActivity mxActivity)
    {
        startPage();
        LambdaQueryWrapper<MxActivity> lqw = new LambdaQueryWrapper<MxActivity>();
        if (StringUtils.isNotBlank(mxActivity.getPbid())){
            lqw.eq(MxActivity::getPbid ,mxActivity.getPbid());
        }
        if (StringUtils.isNotBlank(mxActivity.getTitle())){
            lqw.eq(MxActivity::getTitle ,mxActivity.getTitle());
        }
        if (mxActivity.getTime() != null){
            lqw.eq(MxActivity::getTime ,mxActivity.getTime());
        }
        if (StringUtils.isNotBlank(mxActivity.getPosition())){
            lqw.eq(MxActivity::getPosition ,mxActivity.getPosition());
        }
        if (StringUtils.isNotBlank(mxActivity.getLabel())){
            lqw.eq(MxActivity::getLabel ,mxActivity.getLabel());
        }
        if (StringUtils.isNotBlank(mxActivity.getImg())){
            lqw.eq(MxActivity::getImg ,mxActivity.getImg());
        }
        if (StringUtils.isNotBlank(mxActivity.getDetail())){
            lqw.eq(MxActivity::getDetail ,mxActivity.getDetail());
        }
        if (mxActivity.getViews() != null){
            lqw.eq(MxActivity::getViews ,mxActivity.getViews());
        }
        if (mxActivity.getCollections() != null){
            lqw.eq(MxActivity::getCollections ,mxActivity.getCollections());
        }
        if (mxActivity.getLikes() != null){
            lqw.eq(MxActivity::getLikes ,mxActivity.getLikes());
        }
        if (mxActivity.getUnlikes() != null){
            lqw.eq(MxActivity::getUnlikes ,mxActivity.getUnlikes());
        }
        if (mxActivity.getComments() != null){
            lqw.eq(MxActivity::getComments ,mxActivity.getComments());
        }
        if (mxActivity.getChecked() != null){
            lqw.eq(MxActivity::getChecked ,mxActivity.getChecked());
        }
        if (mxActivity.getDeleted() != null){
            lqw.eq(MxActivity::getDeleted ,mxActivity.getDeleted());
        }
        List<MxActivity> list = iMxActivityService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出美秀活动列表
     */
    @PreAuthorize("@ss.hasPermi('mx:activity:export')" )
    @Log(title = "美秀活动" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public R export(MxActivity mxActivity) {
        LambdaQueryWrapper<MxActivity> lqw = new LambdaQueryWrapper<MxActivity>(mxActivity);
        List<MxActivity> list = iMxActivityService.list(lqw);
        ExcelUtil<MxActivity> util = new ExcelUtil<MxActivity>(MxActivity. class);
        return util.exportExcel(list, "activity" );
    }

    /**
     * 获取美秀活动详细信息
     */
    @PreAuthorize("@ss.hasPermi('mx:activity:query')" )
    @GetMapping(value = "/{id}" )
    public R getInfo(@PathVariable("id" ) String id) {
        return R.success(iMxActivityService.getById(id));
    }

    /**
     * 新增美秀活动
     */
    @PreAuthorize("@ss.hasPermi('mx:activity:add')" )
    @Log(title = "美秀活动" , businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody MxActivity mxActivity) {
        return toAjax(iMxActivityService.save(mxActivity) ? 1 : 0);
    }

    /**
     * 修改美秀活动
     */
    @PreAuthorize("@ss.hasPermi('mx:activity:edit')" )
    @Log(title = "美秀活动" , businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody MxActivity mxActivity) {
        return toAjax(iMxActivityService.updateById(mxActivity) ? 1 : 0);
    }

    /**
     * 删除美秀活动
     */
    @PreAuthorize("@ss.hasPermi('mx:activity:remove')" )
    @Log(title = "美秀活动" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public R remove(@PathVariable String[] ids) {
        return toAjax(iMxActivityService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
